Skip to content

Fix currency input regex + migrate to storybook/test v9#10

Merged
jaruesink merged 3 commits into
mainfrom
fix/currency-input-regex
Jul 14, 2026
Merged

Fix currency input regex + migrate to storybook/test v9#10
jaruesink merged 3 commits into
mainfrom
fix/currency-input-regex

Conversation

@jaruesink

@jaruesink jaruesink commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Changes

1. Tighten currency input number parsing

The old regex /[^0-9.-]+/g was too permissive — it allowed multiple decimal points (1.2.3) and minus signs anywhere (1-2-3). Replaced with a two-stage parse:

  • Strip non-numeric characters
  • Clamp to valid number format via /^-?\d*\.?\d*/ (optional leading minus, digits, optional single decimal point + digits)

2. Migrate @storybook/teststorybook/test (v9)

Storybook 9 merged test utilities into the main storybook package. Removed the old @storybook/test@8.6.14 and @storybook/testing-library packages, updated imports in story files. Eliminates the SB9 compatibility warning at startup.

Test results

Test Suites: 7 passed, 7 total
Tests:       51 passed, 51 total

Summary by CodeRabbit

  • Bug Fixes

    • Improved currency input parsing by tightening numeric cleaning/validation to reject malformed values (e.g., inputs like 1.2.3 or 1-2-3) while keeping typing behavior consistent.
    • Continued to apply value transformations when enabled, using the sanitized numeric string.
  • Chores

    • Updated Storybook testing configuration by removing the dedicated Storybook test dependency and adjusting related test setup, with no changes to story content or behavior.

- Replace permissive regex with two-stage parse: strip non-numeric,
  then clamp to valid number format (optional leading minus, single
  decimal point). Prevents malformed input like '1.2.3' or '1-2-3'.
- Remove @storybook/test (v8) and @storybook/testing-library,
  migrate imports to storybook/test (v9 path). Eliminates SB9
  compatibility warning.
- All 51 interaction tests pass.
@github-actions

Copy link
Copy Markdown
Contributor

📝 Storybook Preview: View Storybook

This preview will be updated automatically when you push new changes to this PR.

Note: The preview will be available after the workflow completes and the PR is approved for deployment.

- Extract regex literals to module-level constants (biome/useTopLevelRegex)
- Fix import ordering in story files (biome/organizeImports)
- All 51 tests still passing
@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

The change tightens controlled currency input parsing with shared regex constants, removes a redundant Storybook test dependency, reorders story imports, and records a patch release changeset.

Changes

Currency input and docs test cleanup

Layer / File(s) Summary
Numeric currency input parsing
packages/medusa-forms/src/controlled/ControlledCurrencyInput.tsx, .changeset/currency-input-fix.md
Adds shared numeric regex constants, extracts numeric-shaped input after cleaning, and documents the patch release and parsing fix.
Documentation test setup cleanup
apps/docs/package.json, apps/docs/src/medusa-forms/*.stories.tsx
Removes @storybook/test and reorders imports in the affected Storybook stories.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the two main changes: currency input regex tightening and migration to Storybook test v9.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/currency-input-regex

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.changeset/currency-input-fix.md:
- Around line 5-8: Update the changeset for `@lambdacurry/medusa-forms` to cover
only the published currency-input behavior; remove the internal Storybook/test
v9 migration from the release note. In the currency parsing description, refer
to normalization of malformed values, including stripping non-numeric characters
and clamping the format, rather than claiming they are rejected.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9c96cebe-66b5-429a-85ad-2817eb242c7e

📥 Commits

Reviewing files that changed from the base of the PR and between e527c4a and 7160a99.

📒 Files selected for processing (1)
  • .changeset/currency-input-fix.md

Comment on lines +5 to +8
Fix currency input regex to reject malformed numbers and migrate to storybook/test v9

- Tighten number parsing: strip non-numeric, then clamp to valid format (no more `1.2.3` or `1-2-3`)
- Migrate `@storybook/test@8` → `storybook/test` (v9), removing compatibility warning

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Keep the changeset scoped to the published package and actual behavior.

@lambdacurry/medusa-forms is the only package in the frontmatter, but the Storybook migration is an internal docs change. Also, ControlledCurrencyInput.tsx:6-48 normalizes/truncates malformed values rather than rejecting them. Keep this release note focused on currency parsing and describe the behavior as normalization.

Suggested wording
-Fix currency input regex to reject malformed numbers and migrate to storybook/test v9
+Normalize malformed currency input to a single numeric value
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.changeset/currency-input-fix.md around lines 5 - 8, Update the changeset
for `@lambdacurry/medusa-forms` to cover only the published currency-input
behavior; remove the internal Storybook/test v9 migration from the release note.
In the currency parsing description, refer to normalization of malformed values,
including stripping non-numeric characters and clamping the format, rather than
claiming they are rejected.

@jaruesink jaruesink merged commit 4880202 into main Jul 14, 2026
5 checks passed
@jaruesink jaruesink deleted the fix/currency-input-regex branch July 14, 2026 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant